package com.jnshu.controller;

import com.jnshu.dto.course.CourseDto;
import com.jnshu.pojo.Collect;
import com.jnshu.pojo.Course;
import com.jnshu.service.FrontCourseService;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FrontCourseController
 * @Descrintion
 * @Author bd
 * @Date 2019/8/7 15:31
 * @Version 1.0
 **/
@RestController
@Log
public class FrontCourseController {
    @Autowired
    FrontCourseService frontCourseService;

    //文章、视频列表
    @GetMapping("/cotent/list")
    public ResultBean uSelectContentList(CourseDto course, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,Long userId) {
        log.info("controller层文章传入的前台查询参数为course" + course + ",页面数量为" + pageSize + ",页码" + pageNum);
        return frontCourseService.uSelectList(course, pageSize, pageNum,userId);
    }

    //视频、文章搜索
    @GetMapping("/ucotent")
    public ResultBean uSelectContent(CourseDto course, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,Long userId) {
        log.info("controller层文章传入的前台查询参数为course" + course + ",页面数量为" + pageSize + ",页码" + pageNum);
        course.setType(0);
        return frontCourseService.uSelectList(course, pageSize, pageNum,userId);
    }


    //文章详情
    @GetMapping("/cotent/details")
    public ResultBean selectByPrimaryKey(long id,Long userId) {
        log.info("controller层视频传入的前台查询参数id为" + id);
        return frontCourseService.selectByPrimaryKey(id,userId);
    }

    //视频详情
    @GetMapping("/video/details")
    public ResultBean selectByPrimaryKeyVideo(long id,Long userId) {
        log.info("controller层视频传入的前台查询参数id为" + id);
        return frontCourseService.selectByPrimaryKeyVideo(id,userId);
    }

    //收藏
    @PostMapping("/search/collection")
    public ResultBean insert(Integer classify,Long courseId,Long userId) {
        log.info("controller层insert方法传入的参数为" + courseId);
        return frontCourseService.insert(classify,courseId,userId);
    }

    //收藏状态
    @GetMapping("/search/collection")
    public ResultBean selectStatus(Long courseId,Long userId) {
        log.info("controller层selectStatus方法传入的参数courseId为" + courseId);
        return frontCourseService.selectStatus(courseId,userId);
    }

    //取消收藏
    @DeleteMapping("/search/collection")
    public ResultBean deleteStatus(Long courseId,Long userId) {
        log.info("controller层deleteStatus方法传入的courseId为" + courseId);
        return frontCourseService.deleteStatus( courseId,userId);
    }

    //获取记录
    @GetMapping("/search/history")
    public ResultBean getHistory(Integer classify,String userId) {
        log.info("controller层getHistory方法传入的参数classify为" + classify);
        return frontCourseService.getHistory(classify,userId);
    }

    //删除记录
    @DeleteMapping("/search/history")
    public ResultBean deleteHistory(Integer classify,String userId) {
        log.info("controller层deleteHistory方法传入的参数classify为" + classify);
        return frontCourseService.deleteHistory(classify,userId);
    }
}
